package com.framework.buss.bridge.controller;

import com.framework.buss.bridge.model.WordTreeSelected;
import com.framework.buss.bridge.service.IWordTreeSelectedService;
import com.framework.buss.bridge.vo.WordTreeIdVO;
import com.framework.common.domain.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: AI报告word目录表
 * @Author: jeecg-boot
 * @Date:   2023-08-16
 * @Version: V1.0
 */
@Api(tags="AI报告word目录表")
@RestController
@RequestMapping("/bridge/wordTreeSelected")
@Slf4j
public class WordTreeSelectedController {
	@Autowired
	private IWordTreeSelectedService wordTreeSelectedService;


	/**
	 *   添加
	 */
	@ApiOperation(value="AI报告word目录表-获取单个", notes="AI报告word目录表-获取单个")
	@GetMapping(value = "/get")
	public ResultData<WordTreeSelected> get(WordTreeSelected params) {
		WordTreeSelected wordTreeSelected = wordTreeSelectedService.findOne(params);
		return ResultData.data(wordTreeSelected);
	}


	/**
	 *   添加
	 */
	@ApiOperation(value="AI报告word目录表-添加", notes="AI报告word目录表-添加")
	@PostMapping(value = "/add")
	public ResultData<String> add(@RequestBody WordTreeIdVO idVO) {
		wordTreeSelectedService.addWordTreeSelected(idVO);
		return ResultData.success("添加成功！");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="AI报告word目录表-批量删除", notes="AI报告word目录表-批量删除")
    //@RequiresPermissions("org.jeecg.biz.bridge:buss_word_tree_selected:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public ResultData<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.wordTreeSelectedService.removeByIds(Arrays.asList(ids.split(",")));
		return ResultData.success("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="AI报告word目录表-通过id查询", notes="AI报告word目录表-通过id查询")
	@GetMapping(value = "/ids")
	public ResultData<List<String>> queryById(@RequestParam(name="id") String id) {
		List<String> ids = wordTreeSelectedService.getSelectedIdList(id);
		return ResultData.data(ids);
	}

	@ApiOperation(value="AI报告word目录表-编辑单个文档", notes="AI报告word目录表-编辑单个文档")
	@RequestMapping(value = "/loadWord")
	@ResponseBody
	public void loadWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		wordTreeSelectedService.loadWord(request, response);
	}

	@ApiOperation(value="AI报告word目录表-合并模板", notes="AI报告word目录表-合并模板")
	@RequestMapping(value = "/mergeWord")
	@ResponseBody
	public void mergeWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
		wordTreeSelectedService.mergeWord(request, response);
	}
}
